<template>
    <div class="longe-center">
        <div class="longe-nav">
        <div class="box1">
           <img src=".././assets/logo.png" alt="">
        </div>
        <div class="nav">
        <div class="inp">
            <el-form ref="form" :model="form" :rules="rules">
                <el-form-item prop="name">
                <el-input prefix-icon="iconfont icon-user" v-model="form.name"></el-input>
           </el-form-item>
           <el-form-item prop="region">
               <el-input prefix-icon="iconfont icon-lock_fill" type="password" v-model="form.region"></el-input>
            </el-form-item>
        </el-form>
        </div>
           <div class="bon">
              <el-button type="primary" @click="vall">登录</el-button>
              <el-button type="info" @click="reset">重置</el-button>
           </div>
           </div>
        </div>
    </div>
</template>
<script>
export default {
  data () {
    return {
      form: {
        name: '',
        region: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        region: [
          { required: true, message: '请输入密码', trigger: 'change' },
          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    vall () {
      this.$refs.form.validate(async res => {
        if (!res) return this.$message.error('请输入用户名')
        if (res) {
          var obj = { username: this.form.name, password: this.form.region }
          // eslint-disable-next-line no-redeclare
          var { data: ress } = await this.axios.post('login', obj)
          // console.log(ress)
          if (ress.meta.status !== 200) {
            return this.$message.error('请重新输入')
          }
          window.sessionStorage.setItem('token', ress.data.token)
          this.$message({
            message: '恭喜你，这是一条成功消息',
            type: 'success'
          })
          this.$router.push('/home')
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.longe-center{
    height: 100vh;
    background: #2b4b6b;
    position: relative;
.longe-nav{
    height: 300px;
    width: 420px;
    border-radius: 10px;
    background: #fff;
    position: absolute;
    left: 50%;
    top:50%;
    transform: translate(-50%,-50%);
    .box1{
        position: absolute;
        width: 130px;
        height: 130px;
        border-radius: 50%;
        background: #fff;
        border: 10px solid #eee;
        overflow: hidden;
        left: 50%;
        transform: translate(-50%,-50%);
        img{
            width: 100%;
        }
    }
    .nav{
        width: 100%;
        box-sizing: border-box;
        position: absolute;
        padding: 4px 10px;
        bottom: 0;
        .bon{
            display: flex;
            justify-content: flex-end;
        }
    }
}
}
</style>
